#!/bin/sh
cp /boot/config.txt /tmp
grep "enable_uart=1" /tmp/config.txt >/dev/null
if [ $? != 0 ]; then
 echo "enable_uart=1" >> /tmp/config.txt
 CHANGED=1
fi

grep "dtoverlay=uart0" /tmp/config.txt >/dev/null
if [ $? != 0 ]; then
 echo "dtoverlay=uart0" >> /tmp/config.txt
 CHANGED=1
fi


grep "dtoverlay=disable-bt" /tmp/config.txt >/dev/null
if [ $? != 0 ]; then
 echo "dtoverlay=disable-bt" >> /tmp/config.txt
 CHANGED=1
fi

if [ "$CHANGED" != "" ]; then
 mount -o remount,rw /boot
 cp /tmp/config.txt /boot/config.txt
 echo "Rebooting in 5 seconds"
 sleep 5
 sync
 reboot
fi

rm /tmp/config.txt

